<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="../Public/js/axios.js"></script>
    <script src="../Public/js/jquery.js"></script>
    <link rel="stylesheet" href="../Public/css/index-1.css">
    <link rel="stylesheet" href="../Public/css/site.css">
    <link rel="stylesheet" href="../Public/css/index1.css">
    <link rel="stylesheet" href="../Public/css/doc.css">
    <link rel="stylesheet" href="css/detail.css">
    <script src="js/api.js"></script>
</head>
<body >
<div id="app">
    <!--后台获取的内容-->
    <div id="body">
    </div>
    <!--留言-->
    <div class="leaveBox1">
        <h3>我的留言<el-button size="mini" type="primary" class="keep" @click="ok">保存</el-button></h3>
        <el-input type="textarea"  :rows="2" v-model="input" placeholder="请输入留言" style="width: 300px" size="mini"></el-input><br>
        <div v-for="(item,index) in msgList" class="leaveList">
            <p>{{item.msg}}</p>
            <div class="leaveList_detail">
                <p>·   {{item.uname}}</p> <label>{{item.msgtime}}</label>
            </div>
        </div>
    </div>
    <div class="btn">
        <el-button size="mini" type="primary" @click="step">上一步</el-button>
        <el-button :disabled="istrue == 1" size="mini" type="info" @click="adopt">下一步</el-button>
    </div>
    <!--弹出框-->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="20%">
        <div class="diaBox">
            <el-button v-for="(item, index) in userItem" class="btnBox_btn" @click="clickBtn(item)">{{index+1}}:{{item.uname}}</el-button>
        </div>
    </el-dialog>
</div>


</body>
<script>
    new Vue({
        el: '#app',
        data: {
            dialogVisible: false,
            input: '',
            id: '',
            msgList: [],
            userItem: [],
            sid: '',
            uid: '',
            istrue: '',
            flowid: ''
        },
        created() {
            this.value()
            this.detail()
        },
        methods: {
            // 点击用户
            clickBtn(a) {
                axios({
                    methods: 'post',
                    url: Api + 'sp/back',
                    params: {
                        sid: this.sid,
                        flowid: this.flowid,
                        node: a.node
                    }
                }).then(res=>{
                    if (res.status == '200') {
                        this.$message({
                            type: 'success',
                            message: res.data.data
                        })
                        this.dialogVisible = false
                        setTimeout(function () {
                            location.href = './list.html'
                        },1000)
                    } else {
                        this.$message({
                            type: 'error',
                            message: res.data.data
                        })
                    }
                })
            },
            //   下一步
            adopt(){
                axios({
                    method: 'post',
                    url: Api + 'sp/goNextNode',
                    params:{
                        userid: this.uid,
                        flowid: this.flowid
                    }
                }).then(res=>{
                    console.log(res)
                    if (res.status == '200') {
                        if (res.data.data == '300') {
                            this.$message({
                                type: 'success',
                                message: '审核通过！'
                            })
                        } else {
                            this.$message({
                                type: 'success',
                                message: res.data
                            })
                        }
                        setTimeout(function () {
                            location.href = './list.html'
                        },2000)
                    } else {
                        this.$message({
                            type: 'error',
                            message: res.data
                        })
                    }
                })
            },
            //  上一步
            step() {
                this.dialogVisible = true
                if (localStorage.getItem("uid")) {
                    this.userList(localStorage.getItem("uid"))
                }
            },
            // 用户节点列表
            userList(a) {
                axios({
                    methods: 'post',
                    url: Api + 'sp/findFlowNode',
                    params: {
                        uid: a,
                        sid: this.flowid
                    }
                }).then(res=>{
                    console.log(res);
                    this.userItem = res.data

                })
            },
            // 保存
            ok () {
                if (!this.input) {
                    this.$message({
                        type:"warning",
                        message: '留言不能为空！'
                    })
                    return
                }
                axios({
                    method: 'post',
                    url: Api + 'sp/flowSetMsg',
                    params: {
                        sid: this.id,
                        msg: this.input
                    }
                }).then(res=>{
                    if (res.status == '200') {
                        this.$message({
                            type: 'success',
                            message: res.data.data
                        })
                        this.detail()
                    } else {
                        this.$message({
                            type: 'error',
                            message: res.data.data
                        })
                    }
                })
            },
            // 返回上一级
            back() {
                window.history.back(-1)
            },
            // 页面取值
            value() {
                if(window.location.search){
                    this.id  = window.location.search.split('?')[1].split("=")[1]
                }
            },
            //  详情
            detail(){
                axios({
                    method: 'post',
                    url: Api + 'sp/findByid',
                    params: {
                        sid: this.id
                    }
                }).then(res=>{
                    console.log(res)
                    this.sid = res.data.id
                    this.uid = res.data.uid
                    this.flowid = res.data.f_id
                    this.istrue = res.data.state
                    var html = res.data.html
                    $("#body").html(html)
                    this.msgList = res.data.msgList
                })
            }
        }
    })
</script>
</html>